<?php
$userDetails = '';
$classCourseId = '';
$userId='';
if (isset($data->purchaseClassCourses[0]->classes_id) && $data->purchaseClassCourses[0]->classes_id != '') {
    $imagePath = getImagePathByClassCourse('Classes', $data->purchaseClassCourses[0]->classes_id);
    $userDetails = getUserTypeByClassCourse('Classes', $data->purchaseClassCourses[0]->classes_id);
    $classImage = ClassImage::getPrimaryImage($data->purchaseClassCourses[0]->classes_id);
    $classTitle = getClassName($data->purchaseClassCourses[0]->classes_id);
    $seourl=getClaCourseInfo('Classes',$data->purchaseClassCourses[0]->classes_id);
    $classCourseId = $data->purchaseClassCourses[0]->classes_id;
    $classModel = getClaCourseInfo('Classes', $data->purchaseClassCourses[0]->classes_id);
    $authKey = $classModel->auth_key;
    $userId = ($classModel->users_id == '') ? $classModel->backend_user_id : $classModel->users_id;
    $userType = ($classModel->users_id == '') ? 'backend' : '';
    $classType = 'classId';
    $imageName = (!empty($classImage)) ? getRequestbaseUrl() . getuploadFolderDir() . SkillConfig::getClassCourseImagePath($imagePath) . 'details-image/' . $classImage : getWorkNoshopimage(SkillConfig::skill_learn_page);

$puracheId = $data->id . $userId;
$criteria = new CDbCriteria();
$criteria->condition = 'courses_id IS NULL AND classes_id IS NULL AND (to_front_user_id=' . $userId . ' OR to_back_user_id=' . $userId . ')';
$criteria->addCondition('from_user_id=' . getLoginUserId());
$rateToTrainer = ClassCourseTrainnerRate::model()->find($criteria);
$classcriteria = new CDbCriteria();
$classcriteria->condition = 'to_front_user_id IS NULL AND  to_back_user_id IS  NULL AND (courses_id=' . $classCourseId . ' OR classes_id=' . $classCourseId . ')';
$classcriteria->addCondition('from_user_id=' . getLoginUserId());
$classcriterias = ClassCourseTrainnerRate::model()->find($classcriteria);
 ?>


<div class="col-lg-4 col-md-4 col-sm-4 col-xs-12 column4">
    <div class="learn-title">
        <a href="<?php echo ($classCourseId != '') ? $this->createAbsoluteUrl('workshop-'.$classCourseId.'/'.$seourl->class_seo_title) : $this->createAbsoluteUrl('courses/viewCourse', array('id' => ' ')) ?>">
            <img src="<?php echo $imageName; ?>" alt="" class="img-responsive">   
            <span><?php echo substrclasscourname($classTitle); ?><small>By <?php echo $userDetails->first_name . ' ' . $userDetails->last_name; ?><br>Order: Date <?php echo date('d M Y', strtotime($data->order_date_time)); ?><br>
                    price:<?php echo ($classCourseId != '') ? ClassBatch::findMinMaxPriceByClassbatchforCategoryPage($classCourseId) : CourseBatche::findMinMaxPriceByClassbatchforCategoryPage(' ') ?></small></span>
        </a>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 column6 pad-rl learn-page-anchor">
            <?php echo ($classCourseId != '') ? CHtml::link('view class detail', $this->createAbsoluteUrl('workshop-'.$classCourseId.'/'.$seourl->class_seo_title)) : CHtml::link('view course detail', $this->createAbsoluteUrl('courses/viewCourse', array('id' => ' '))) ?>

        </div>
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 column6 pad-rl learn-page-anchor" >
            <?php echo CHtml::link('view trainer detail', $this->createAbsoluteUrl('users/trainerProfile', array('authKey' => $authKey))); ?>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 column6 pad-rl">
            <input type="button" value="Review class"  onclick="puracheClassReview(<?php echo $puracheId; ?>)"/>
        </div>
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 column6 pad-rl">
            <input type="button" value="Review trainer" onclick="purachgeClassTrainerReview(<?php echo $puracheId; ?>)"/>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 rating column6">
            Rate class
            <div class="star-rating">
                <?php
                if (!empty($classcriterias)) {
                    for ($classrate = 1; $classrate <= $classcriterias->status; $classrate++) {
                        ?>
                        <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . $classrate; ?>" value="<?php echo $classrate; ?>" ><label for="strss_<?php echo $puracheId . $classrate ?>" style="background:#efc623;"></label></span>
                        <?php
                    } if ($classcriterias->status < 5) {
                        $newTrainerRateCount = 5 - $classcriterias->status;
                        for ($newclassrate = 1; $newclassrate <= $newTrainerRateCount; $newclassrate++) {
                            ?>
                            <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . $newclassrate; ?>" value="<?php echo $newclassrate; ?>" ><label for="strss_<?php echo $puracheId . $newclassrate ?>"></label></span>
                            <?php
                        }
                    }
                } else {
                    ?>
                    <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . '5'; ?>" value="5" onclick="onclickRateToClass(this.id,<?php echo $classCourseId; ?>, '<?php echo $classType; ?>')"><label for="strss_<?php echo $puracheId . '5' ?>"></label></span>
                    <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . '4'; ?>" value="4" onclick="onclickRateToClass(this.id,<?php echo $classCourseId; ?>, '<?php echo $classType; ?>')"><label for="strss_<?php echo $puracheId . '4'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . '3'; ?>" value="3" onclick="onclickRateToClass(this.id,<?php echo $classCourseId; ?>, '<?php echo $classType; ?>')"><label for="strss_<?php echo $puracheId . '3'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . '2'; ?>" value="2" onclick="onclickRateToClass(this.id,<?php echo $classCourseId; ?>, '<?php echo $classType; ?>')"><label for="strss_<?php echo $puracheId . '2'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="strss_<?php echo $puracheId . '1'; ?>" value="1" onclick="onclickRateToClass(this.id,<?php echo $classCourseId; ?>, '<?php echo $classType; ?>')"><label for="strss_<?php echo $puracheId . '1'; ?>"></label></span>
                <?php } ?></div> 
        </div>
        <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 rating column6">
            Rate trainer
            <div class="star-rating">
                <?php
                if (!empty($rateToTrainer)) {
                    for ($rate = 1; $rate <= $rateToTrainer->status; $rate++) {
                        ?>
                        <span><input type="radio" name="rating" id="str_<?php echo $puracheId . $rate; ?>" value="<?php echo $rate; ?>" ><label for="str_<?php echo $puracheId . $rate ?>" style="background:#efc623;"></label></span>
                        <?php
                    } if ($rateToTrainer->status < 5) {
                        $newTrainerRateCount = 5 - $rateToTrainer->status;
                        for ($newrate = 1; $newrate <= $newTrainerRateCount; $newrate++) {
                            ?>
                            <span><input type="radio" name="rating" id="str_<?php echo $puracheId . $newrate; ?>" value="<?php echo $newrate; ?>" ><label for="str_<?php echo $puracheId . $newrate ?>"></label></span>
                            <?php
                        }
                    }
                } else {
                    ?>
                    <span><input type="radio" name="rating" id="str_<?php echo $puracheId . '5'; ?>" value="5" onclick="rateTotarinner(this.id, '<?php echo $userType; ?>', '<?php echo $userId; ?>')"><label for="str_<?php echo $puracheId . '5' ?>"></label></span>
                    <span><input type="radio" name="rating" id="str_<?php echo $puracheId . '4'; ?>" value="4" onclick="rateTotarinner(this.id, '<?php echo $userType; ?>', '<?php echo $userId; ?>')"><label for="str_<?php echo $puracheId . '4'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="str_<?php echo $puracheId . '3'; ?>" value="3" onclick="rateTotarinner(this.id, '<?php echo $userType; ?>', '<?php echo $userId; ?>')"><label for="str_<?php echo $puracheId . '3'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="str_<?php echo $puracheId . '2' ?>" value="2" onclick="rateTotarinner(this.id, '<?php echo $userType; ?>', '<?php echo $userId; ?>')"><label for="str_<?php echo $puracheId . '2'; ?>"></label></span>
                    <span><input type="radio" name="rating" id="str_<?php echo $puracheId . '1' ?>" value="1" onclick="rateTotarinner(this.id, '<?php echo $userType; ?>', '<?php echo $userId; ?>')"><label for="str_<?php echo $puracheId . '1'; ?>"></label></span>
                <?php } ?></div> 
        </div>
    </div>  
    <div class="row purchageUserClass" style="display: none" id="purchage-class_review_<?php echo $puracheId ?>">
        <div class="errorMessage" id="successpurchage_class_review_<?php echo $puracheId ?>"></div>
        <div id="loaderpurchage_class_review_<?php echo $puracheId ?>" style="display: none"><img src="<?php echo ThemePath(); ?>/images/sitciyloder.gif"></div>
        <div class=" column4 write-review ">
            <hr>
            <textarea class="form-control book-control" placeholder="write a review to class..." id="purchage-class_reviewtext_<?php echo $puracheId ?>"></textarea>
            <div class="errorMessage" id="purchage-class_review_error_<?php echo $puracheId ?>"></div>
            <div class="clearfix"></div>
            <div class="gap"></div>
            <div class="button-cont">
                <a class="button-format" href="javascript:void(0);" onclick="purachgeClassReviewValidate(<?php echo $puracheId; ?>,<?php echo $classCourseId; ?>,<?php echo ($classCourseId != '') ? "'classId'" : "'courseId'"; ?>)" >Submit</a>
                <a class="button-format" href="javascript:void(0);" onclick="cancelQuery('purchage-class_review_<?php echo $puracheId ?>')">Cancel</a>
            </div>
        </div>
    </div>
    <div class="row purchageUserClass" id="purchage-class_<?php echo $puracheId ?>" style="display: none">
        <div class="errorMessage" id="successpurchage_review_<?php echo $puracheId ?>"></div>
        <div id="loaderpurchage_review_<?php echo $puracheId ?>" style="display: none"><img src="<?php echo ThemePath(); ?>/images/sitciyloder.gif"></div>

        <div class=" column4 write-review ">
            <hr>
            <textarea class="form-control book-control" placeholder="write a review to trainer" id="purchage-class_trainer_reviewtext_<?php echo $puracheId ?>"></textarea>
            <div class="errorMessage" id="purchage-class_trainer_error_<?php echo $puracheId ?>"></div>
            <div class="clearfix"></div>
            <div class="gap"></div>
            <div class="button-cont">
                <a class="button-format" href="javascript:void(0);" onclick="purachgeClassTrainerValidate(<?php echo $puracheId; ?>,<?php echo $userId; ?>,<?php echo "'$userType'"; ?>)" >Submit</a>
                <a class="button-format" href="javascript:void(0);" onclick="cancelQuery('purchage-class_<?php echo $puracheId ?>')">Cancel</a>
            </div>
        </div>
    </div>


</div>

<?php }?>

